<template>
  <ele-modal
    :width="550"
    :visible="visible"
    :confirm-loading="loading"
    :title="'完成维修'"
    :body-style="{ paddingBottom: '8px' }"
    @update:visible="updateVisible"
    :footer="null"
  >
    <a-form
      :label-col="{ md: { span: 5 }, sm: { span: 4 }, xs: { span: 24 } }"
      :wrapper-col="{ md: { span: 17 }, sm: { span: 20 }, xs: { span: 24 } }"
    >
      <a-row :gutter="24">
        <a-col :md="24" :sm="24" :xs="24">
          <a-form-item label="维修地点" >
            <div>{{info.repair_type_name || ''}}</div>
          </a-form-item>
          <a-form-item label="实际维修项目">
            <div>{{info.real_repair_item_code_name || ''}}</div>
          </a-form-item>
          <a-form-item label="预估维修费用">
            <div>{{info.repair_evaluate || ''}}</div>
          </a-form-item>
          <a-form-item label="实际维修费用"  v-bind="validateInfos.real_amount">
            <a-input
              allow-clear
              placeholder="请输入"
              v-model:value="form.real_amount"
              autocomplete="off"
            />
          </a-form-item>
          <a-form-item label="维修成本">
            <a-input
              allow-clear
              placeholder="请输入"
              v-model:value="form.cost"
              autocomplete="off"
            />
          </a-form-item>
        </a-col>
		<a-col :md="24" :sm="24" :xs="24">
			<div class="margin-15" style="float:right">
				<a-space>
					<a-button type="primary" @click="save()">保存</a-button>
					<a-button @click="updateVisible(false)">取消</a-button>
				</a-space>
			</div>
        </a-col>
      </a-row>
    </a-form>
  </ele-modal>
</template>

<script setup>
  import { ref, reactive, onMounted } from 'vue';
  import { Form, message } from 'ant-design-vue';
  import { get_repair_order_detail } from '@/api/order/repair_order';
  // 表格列配置
  const useForm = Form.useForm;

  const emit = defineEmits(['done', 'update:visible']);

  const props = defineProps({
    // 弹窗是否打开
    visible: Boolean,
	order_sn: String
  });

  // 提交状态
  const loading = ref(false);
  const info = ref({});

  // 表单数据
  const form = reactive({
    order_sn:props.order_sn,
    real_amount:'',
    cost:''
  });
  
  onMounted(()=>{
	  get_repair_order_detail({order_sn:props.order_sn}).then(res=>{
		  info.value = res;
	  })
  })

  // 表单验证规则
  const rules = reactive({
    real_amount: [
      {
        required: true,
        message: '请输入实际维修费用',
        type: 'string',
        trigger: 'change'
      }
    ]
  });

  const { validate, validateInfos } = useForm(form, rules);

  /* 保存*/
  const save = () => {
    validate()
      .then(() => {
        emit('done', form);
      })
      .catch(() => {});
  };
  /* 更新visible */
  const updateVisible = (value) => {
    emit('update:visible', value);
  };
</script>
<style scoped></style>
